/*
 * This file is part of aion-lightning <aion-lightning.org>.
 *
 *  aion-lightning is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-lightning is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-lightning.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.services.siegeservice;

import com.aionengine.gameserver.model.gameobjects.siege.SiegeNpc;
import com.aionengine.gameserver.model.siege.SiegeLocation;
import com.aionengine.gameserver.model.siege.SiegeRace;

import java.util.concurrent.Future;

/**
 * @author Luzien
 */
public abstract class Assault<siege extends Siege<?>> {

    protected final SiegeLocation siegeLocation;
    protected final int locationId;
    protected final SiegeNpc boss;
    protected final int worldId;

    protected Future<?> dredgionTask;
    protected Future<?> spawnTask;

    public Assault(Siege<?> siege) {
        this.siegeLocation = siege.getSiegeLocation();
        this.boss = siege.getBoss();
        this.locationId = siege.getSiegeLocationId();
        this.worldId = siege.getSiegeLocation().getWorldId();
    }

    public int getWorldId() {
        return worldId;
    }

    public void startAssault(int delay) {
        scheduleAssault(delay);
    }

    public void finishAssault(boolean captured) {
        if (dredgionTask != null && !dredgionTask.isDone())
            dredgionTask.cancel(true);
        if (spawnTask != null && !spawnTask.isDone())
            spawnTask.cancel(true);

        onAssaultFinish(captured && siegeLocation.getRace().equals(SiegeRace.BALAUR));
    }

    protected abstract void onAssaultFinish(boolean captured);

    protected abstract void scheduleAssault(int delay);

}